% test run
% by Sun Sibai
strs={'1080598.txt';'1141410.txt';'502309.txt';'1141261.txt'};
ks=[5,10,15,20,25,30,35,40];
if (exist('out','dir')==0)
 mkdir('out');
end
for str=1:size(strs,1)
 str=cell2mat(strs(str));
 X=importfile(str);
 A=swloadsp(X);
 M=A*A'+A'*A;
 W=swnormal(M);
 for k=ks
  [H,iter,err]=symnmf_anls(W,k,struct('debug',2));
  H=full(H);
  plot(H);
  disp('Cluster Statistics: Sorted Average Paper Occupation:');
  [c,u]=sort(sum(H));
  disp(c);
  Hs=zeros(size(H));
  for it=1:size(u,2)
   Hs(:,it)=H(:,u(it));
  end
  [Max,Idx]=max(abs(Hs'));
  Idx=Idx+20*(Max==0);
  Idx=Idx';
  save(strcat('out/',str,'.k',sprintf('%d',k),'.idx.txt'),'Idx','-ascii');
  save(strcat('out/',str,'.k',sprintf('%d',k),'.H.txt'),'Hs','-ascii');
 end
end
